//
//  ByViewDayEarningPointSwitch.m
//  mijifen_ios
//
//  Created by mc on 2017/10/30.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewDayEarningPointSwitch.h"


@implementation ByViewDayEarningPointSwitch

- (instancetype)init{
    if (self = [super init]) {
        self.popMode = ZKBombPopModeTop;
        self.positionMode = ZKBombPositionModeCenter;
        self.damping = 0.6;
        self.aniDuration = 0.8;
        
    }
    return self;
}

- (void)setPoint:(NSString *)point{
    _point = point;
    [self setupContents];
}

- (void)setupContents{
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 40, 240)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 4.0;
    // 提示 height:45
    UILabel *alertLabel = [[UILabel alloc] init];
    [bgView addSubview:alertLabel];
    [alertLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_top);
        make.left.equalTo(bgView.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 40, 45));
    }];
    alertLabel.text= @"提示";
    alertLabel.backgroundColor = BY_THEME_COLOR;
    alertLabel.textColor = BY_TEXT_COLOR;
    alertLabel.font = B_FONT(24);
    alertLabel.textAlignment = NSTextAlignmentCenter;
    
 
    
    // 确定 height:45
    UIButton *sureButton = [[UIButton alloc] init];
    [bgView addSubview:sureButton];
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 40) / 2, 45));
        make.bottom.equalTo(bgView.mas_bottom);
    }];
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    [sureButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    sureButton.backgroundColor = BY_THEME_COLOR;
    sureButton.titleLabel.font = FONT(24);
    
    // 取消 height:45
    UIButton *cancelButton = [[UIButton alloc] init];
    [bgView addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(sureButton.mas_right);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 40) / 2, 45));
        make.bottom.equalTo(bgView.mas_bottom);

    }];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    cancelButton.backgroundColor = [UIColor lightGrayColor];
    cancelButton.titleLabel.font = FONT(24);
    
    
    // 积分 height
    UILabel *pointLabel = [[UILabel alloc] init];
    [bgView addSubview:pointLabel];
    __block CGFloat width = [_point getSizeOfString:24].width + 10;
    [pointLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(alertLabel.mas_bottom).offset(15);
        make.left.equalTo(bgView.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];
    pointLabel.text = _point;
    pointLabel.font = FONT(24);
    
    UIImageView *pointImg = [[UIImageView alloc] init];
    [bgView addSubview:pointImg];
    [pointImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pointLabel.mas_top);
        make.left.equalTo(pointLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    pointImg.image = [UIImage imageNamed:@"Message_point"];
    
    // 互换图片
    UIImageView *switchImg = [[UIImageView alloc] init];
    [bgView addSubview:switchImg];
    [switchImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left).offset((SCREEN_WIDTH - 40 - 60) / 2);
        make.top.equalTo(pointLabel.mas_bottom).offset(5);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    switchImg.image = [UIImage imageNamed:@"DayEarning_switch"];

    NSString *str = [NSString stringWithFormat:@"¥%@",_point];
    width = [str getSizeOfString:24].width + 10;
    UILabel *priceLabel = [[UILabel alloc] init];
    [bgView addSubview:priceLabel];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(switchImg.mas_bottom).offset(5);
        make.right.equalTo(bgView.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];
    priceLabel.font = FONT(24);
    priceLabel.text = str;
    priceLabel.textAlignment = NSTextAlignmentRight;
    
    self.contentView = bgView;

    [sureButton addTarget:self action:@selector(sureAction) forControlEvents:UIControlEventTouchUpInside];
    [cancelButton addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)sureAction{
    if (self.sureBlock) {
        self.sureBlock();
    }
 
}

- (void)cancelAction{
    [self remove];
}

@end
